Skip to content

fix(sourcemap): map columns inside code copied through unchanged - #744

Open
ashley-hunter wants to merge 1 commit into
voidzero-dev:mainfrom
ashley-hunter:fix/sourcemap-columns
Open

ashley-hunter wants to merge 1 commit into
voidzero-dev:mainfrom
ashley-hunter:fix/sourcemap-columns

Conversation

@ashley-hunter

Copy link
Copy Markdown
Collaborator

Summary

When the compiler copies source through unchanged (class members, method bodies), add_line_mappings_for_segment only added a mapping at the start of each segment and at column 0 of each line. Any position inside a line, such as an indented throw or a mid-line call, resolved to column 0 of its line.

That is enough for a debugger stepping by line, but not for tools that resolve a single generated position, such as stack trace symbolication: the frame lands on the right line with no column, and tools that treat a column-0 mapping as missing show no mapping at all.

Fix

Within an unchanged segment, also add a mapping at the start of each token on a line: each run of word characters and each punctuation character. Whitespace gets no mapping. Columns advance in UTF-16 code units, as LineColCursor already counts them. The generated code is unchanged; only the map gains entries.

Test

test_sourcemap_maps_columns_inside_unchanged_code compiles a component and looks up the generated position of an indented throw and of a mid-line call that follows a non-BMP character (two UTF-16 code units). Each must map to its own source column. It also checks that a position inside a word or on whitespace resolves to the token it belongs to, so the map stays one entry per token rather than per character.

  • Before the fix, the test fails: the throw maps to (10, 0) instead of (10, 12).
  • Mutating the new lines one at a time (dropping the token mapping, negating its conditions, removing the column advance, counting characters instead of UTF-16 units) fails the test in each case.
  • cargo test -p oxc_angular_compiler passes.

On a real component file, the map for the same output goes from 33 to 245 entries, and a stack frame inside a method body now resolves to its own column instead of column 0.

Unchanged source segments were mapped only at the segment start and at
column 0 of each line, so a position inside a line (an indented `throw`, a
mid-line call) resolved to the start of its line. Tools that symbolicate a
single position, such as a stack frame, lost the column for component code.

Add a mapping at the start of each token within a line: each run of word
characters and each punctuation character, skipping whitespace, with columns
in UTF-16 code units as `LineColCursor` counts them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant